package com.lrd.rmq514version.job;

import com.lrd.rmq514version.rmq.service.RmqService;
import com.lrd.rmq514version.rmq.vo.SendMoreDelayTimeMsgVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class DelayTimeProducerJob {

    private static final Logger logger = LoggerFactory.getLogger(DelayTimeProducerJob.class);

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private RmqService rmqService;

    @Scheduled(cron = "0 0 0/1 * * ?")
    public void producerJob() {
        logger.info("定时发送mq延时消息开始" + LocalDateTime.now().format(formatter));
        SendMoreDelayTimeMsgVo delayTimeMsgVo = new SendMoreDelayTimeMsgVo();
        delayTimeMsgVo.setMessage("DelayTimeProducerJob定时发送mq延时消息");
        delayTimeMsgVo.setSize(1000);
        rmqService.sendMoreDelayTimeMessage(delayTimeMsgVo);
        logger.info("定时发送mq延时消息结束" + LocalDateTime.now().format(formatter) + "，发送" + delayTimeMsgVo.getSize() + "条");
    }
}
